package com.itheima.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;

import java.io.IOException;

//@WebFilter(urlPatterns = "/emps/*")
public class DemoFilter implements Filter {
    @Override
    //初始化方法 只调用一次
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
        System.out.println("初始化方法init()执行了");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("doFilter()执行了  Demo 拦截到前请求");

        //放行
        filterChain.doFilter(servletRequest,servletResponse);

        System.out.println("doFilter()执行了  Demo拦截到后请求");
    }

    @Override
    //销毁方法 只调用一次
    public void destroy() {
        Filter.super.destroy();
        System.out.println("销毁方法执行了");
    }
}
